OB.Emes_ActionButton = OB.Emes_ActionButton || {};

var QualityPutdata = {};
var QualityResultId = "";
var QualityView = null;

// 设备备品配件盘点审核是否通过
OB.Emes_ActionButton.QualityResult = function(d, b) {
	var e = b.activeView.viewGrid;
	var a = e.getSelectedRecord();
	OB.Emes_ActionButton.MyRefresh=function(){
		b.refresh();
	}
	if (a != null) {
			// 选择纪录行
			var selectRecords = {
				"ASN_CODE" : a.code,   				//物料编码
				"M_NAME" : a.name,		//物料名称
				"M_NUMBER" : a.numbers,			//库存数量
				"M_QTY" : a.profitLossNumbers,					//盘点数量
			};
			QualityResultId = a.id;
			kucunnumbers = a.numbers;
			pandiannumbers = a.profitLossNumbers;
			QualityPutdata = selectRecords;
			QualityView = b;
			isc.OBEXAPP_QualityResultPopup.create().show();
		
	}else{
		isc.showMessage("请选择记录！");
	}
	
};

// checkbox
isc.defineClass("UsingCheckboxItem", "CheckboxItem");
isc.defineClass('OBEXAPP_QualityResultPopup', isc.OBPopup);

isc.OBEXAPP_QualityResultPopup.addProperties({
	width: 400,
	height: 200,
	align: "center",
	showMinimizeButton : false,
	showMaximizeButton : false,

	initWidget : function() {
		this.qualityResultForm = isc.DynamicForm.create({
			ID : "qualityResult",
			canEdit : true,
			width : "100%",
			height : 200,
			fields : [{
				width : "15%",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : false,
				startRow : true,
				title : '物料编码',
				name : 'ASN_CODE'
			}, {
				width : "25%",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : false,
				startRow : false,
				title : '物料名称',
				name : 'M_NAME'
			}, {
				width : "25%",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : false,
				startRow : false,
				title : '库存数量',
				name : 'M_NUMBER'
			}, {
				width : "25%",
				type : 'text',
				readOnlyDisplay : "static",
				canEdit : false,
				startRow : true,
				title : '盘点数量',
				name : 'M_QTY'
			},{   
				width: '*',type: 'select',title:'审核结果',	  name: 'Quality_status',	 valueMap: {passed: '通过', Notthrough: '不通过'} , readOnlyDisplay:"static",startRow:true
				} ]
		
		});
		
		for(id in QualityPutdata){
			this.qualityResultForm.getField(id).setValue(QualityPutdata[id]);
		}
		
		var _self = this;
		
		this.okButton = isc.OBFormButton.create({
			title : '确定',
			popup : this,
			action : function() {
				qualityResult.saveData();
				var PDSTATUS = this.popup.qualityResultForm.getField('Quality_status').getValue();
				var WUID = QualityResultId;
				var kcqty = kucunnumbers;
				var pdqty = pandiannumbers;
				data ={id:WUID,type:PDSTATUS,kcqtys:kcqty,pdqtys:pdqty}
				var callback = function(response, dome, request){
					OB.Emes_ActionButton.MyRefresh();
					
				};
				OB.RemoteCallManager.call("com.mes.handler.SparepartsResultHandler", data, {}, callback);
				this.popup.closeClick();
			}
		});

		// Cancel Button
		this.cancelButton = isc.OBFormButton.create({
			title : '关闭',
			popup : this,
			action : function() {
				this.popup.closeClick();
			}
		});

		// Add the elements into a layout
		this.items = [ isc.VLayout.create({
			align : "center",
			width : "70%",
			height: 200,
			members : [
				this.qualityResultForm,
				isc.VLayout.create({
					width : "150%",
					height : 100,
					members : [
						this.boxForm,
						isc.HLayout.create({
							width : "100%",
							height : 50,
							align : "center",
							membersMargin : 10,
							marginBottom : 10,
							members : [ this.okButton,  this.cancelButton ]
						})
					]
				})
			]
		})];
		this.Super('initWidget', arguments);
	}
});